import { requestClient } from '#/api/request';

export interface MeasureUnitOptionModel {
  label: string;
  value: string;
  id: string;
}

export interface MeasureUnitProps {
  unitTypes?: string[];
}

export async function loadMeasureUnitApi(unitTypes?: string[]) {
  return requestClient.post(`/measure/unit/page`, {
    unitTypes,
    searchCount: false,
    current: 1,
    size: 50,
    orders: [{ column: 'order_no' }],
  });
}

export async function generateMeasureUnitOptions(unitTypes?: string[]) {
  const measureUnits = await loadMeasureUnitApi(unitTypes);
  const options: Array<MeasureUnitOptionModel> = [];
  measureUnits.records.forEach((element: any) => {
    options.push({
      label: element.name,
      value: element.name,
      id: element.measureUnitId,
    });
  });
  return options;
}
